www.gusucode.com > VC++ Windows不规则窗体编程的实例演示-源码程序 > VC++ Windows不规则窗体编程的实例演示-源码程序/code/DlgBase.cpp

    // DlgBase.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "Irregular.h"
#include "DlgBase.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgBase dialog


CDlgBase::CDlgBase(UINT nID,CWnd* pParent /*=NULL*/)
	: CDialog(nID, pParent)
{
	//{{AFX_DATA_INIT(CDlgBase)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgBase::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgBase)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgBase, CDialog)
	//{{AFX_MSG_MAP(CDlgBase)
	ON_WM_PAINT()
	ON_WM_NCHITTEST()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgBase message handlers

BOOL CDlgBase::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

    /*将窗体大小调整到位图大小一样*/
	m_bmp.LoadBitmap(IDB_BITMAP1);

    BITMAP bm;
    m_bmp.GetBitmap(&bm);

    CRect rtWindow;
    GetWindowRect(&rtWindow);
    rtWindow.right = rtWindow.left+bm.bmWidth;
    rtWindow.bottom =rtWindow.top +bm.bmHeight;
    MoveWindow(&rtWindow);
    
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgBase::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
    CDC picDC;	
    picDC.CreateCompatibleDC (&dc);
    
    CBitmap *pOldBmp;
    pOldBmp = picDC.SelectObject (&m_bmp);
    
    BITMAP bm;
    m_bmp.GetBitmap(&bm);
    
    
   	dc.BitBlt (0,0,bm.bmWidth ,bm.bmHeight,&picDC,0,0,SRCCOPY);
    dc.SelectObject(pOldBmp);     	
	// Do not call CDialog::OnPaint() for painting messages
}

UINT CDlgBase::OnNcHitTest(CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    UINT nResult = CDialog::OnNcHitTest(point);
    
    return nResult == HTCLIENT ? HTCAPTION : nResult;
}